//
//  LeLightRenderer.cpp
//  Leste
//
//  Created by 王乐 on 2022/1/27.
//

#include "LeLightRenderer.h"
#include "glad/glad.h"
#include "LeVBOManager.h"

#include "LeCameraManager.h"

#include "LeLight.h"

LeLightRenderer::LeLightRenderer() {
    
}

LeLightRenderer::~LeLightRenderer()  {
}

void LeLightRenderer::preLoopRender() {
    unsigned int VBO;
    LeVBOManager::findVBO("Cube", VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);
    
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
    glEnableVertexAttribArray(0);
}

void LeLightRenderer::render() {
    glm::mat4 projection =  LeCameraManager::getProjectionMatrix();
    glm::mat4 view = LeCameraManager::getViewMatrix();
    
    m_Shader.useShader();
    m_Shader.setMat4("projection", projection);
    m_Shader.setMat4("view", view);

    glm::mat4 model = m_GameObject->m_Transform.getModelMatrix();
    m_Shader.setMat4("model", model);

    m_Shader.setVec4("color", 10, 10, 10, 1);

    glBindVertexArray(VAO);
    glDrawArrays(GL_TRIANGLES, 0, 36);
}

void LeLightRenderer::postLoopRender() {
    glDeleteVertexArrays(1, &VAO);
}
